<?php
class ControllStatistic
{
	public function addCurrentMatch($stockid, $price, $amount)
	{
		include $_SERVER['DOCUMENT_ROOT'].'scue'.'/configuration.php';
		$sql = "SELECT * FROM currentmatch WHERE (stockid ='$stockid')";
		if(!($result = mysql_query($sql)))	die(mysql_error());
		else
		{
			$row = mysql_fetch_array($result);
			$compare = $price - floatval($row['PriceBegin']);
			$sql = "UPDATE currentmatch SET Amount='$amount', Compare='$compare', Price='$price' WHERE StockID='$stockid'";
			mysql_query($sql);
		}
	}

	public function addCurrentPrice($stockid, $totalprice, $totalamount, $high, $low)
	{
		include $_SERVER['DOCUMENT_ROOT'].'scue'.'/configuration.php';
		$sql = "SELECT * FROM currentprice WHERE (stockid ='$stockid')";
		if(!($result = mysql_query($sql)))	die(mysql_error());
		else
		{
			$row = mysql_fetch_array($result);
			//number_format(0.9123, 2, ".", "")
			$totalprice = (floatval($row['TotalPrice']) + $totalprice);
			$totalamount = (intval($row['TotalAmount']) + $totalamount);
			$average =  $totalprice / $totalamount;
			$average = number_format($average, 1, ".", "");
			if (floatval($row['High']) > $high) $high = floatval($row['High']);
			if (floatval($row['Low']) < $low && floatval($row['Low']) > 0) $low = floatval($row['Low']);
			$sql = "UPDATE currentprice SET
							TotalPrice='$totalprice', 
							TotalAmount='$totalamount', 
							Average='$average',
							High='$high',
							Low='$low'
							WHERE StockID='$stockid'";
			mysql_query($sql);
		}
	}
}
?>